package com.could.minority.model;

import io.rong.models.SdkHttpResult;

import java.util.HashMap;
import java.util.LinkedList;

import com.could.BaseClass;
import com.could.db.DbConn;
import com.could.util.SqlUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class User extends BaseClass{
	String insetSql = "insert into user(id,userid,username,email,password,telephone) values(null,?,?,?,?)";
	private DbConn db=null;
	
	 public User(){
	   super(User.class.getName());
	   db=new DbConn();
	}
	 
	 public User(DbConn db){
		   super(User.class.getName());
		   this.db = db;
		}
	public DbConn getDb() {
		  return db;
	 }
	public void setDb(DbConn db) {
		this.db = db;
	 }
	
	public String register(String username,String passwd,String email,String telephone){
		String result = "";
		
		return result ;
	}
	
	public String getUserInfo(String userid){
		String result = "";
		LinkedList list = new LinkedList();
		SqlUtil sqlutil = new SqlUtil();
		String strsql = "select userid id,username,portrait from user where userid = ?";
		sqlutil.setSql(strsql);
		String params = userid;
		try {
			list =sqlutil.executeParamList(params);
			HashMap<String, String> map = new HashMap<String, String>();
			JsonObject jsonObject = new JsonObject();
			SdkHttpResult result1 = null;
			if(list.size()>0){
				JsonObject json = new JsonObject();
					map = (HashMap) list.get(0);
					String id = map.get("id");
					json.addProperty("id", id);
					json.addProperty("username", map.get("username"));
					json.addProperty("portrait", map.get("portrait"));
					result1 = new SdkHttpResult(200, json.toString());
			}else{
				jsonObject.addProperty("message", "email or password is error");
				 result1 = new SdkHttpResult(104, jsonObject.toString());
			}
			result = result1.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result ;
	}
	
	
	
}
